package com.jams.goodox.activity.common;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.utils.EditTextLimitUtils;
import com.jams.goodox.utils.ToastUtil;

import butterknife.Bind;
import butterknife.OnClick;


public class EditTextActivity extends BaseActivity {

    public static final String ETITLE = "ETITLE";
    public static final String ERIGHT = "ERIGHT";
    public static final String ECONTENT = "ECONTENT";
    public static final String EHINT = "EHINT";
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_send)
    TextView tvSend;
    @Bind(R.id.et_input)
    EditText etInput;

    private String title;
    private String right;
    private String content;
    private String hint;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_edit_text;
    }

    @Override
    protected void init() {
        setTitleVisibility(false);
        title = getIntent().getStringExtra(ETITLE);
        right = getIntent().getStringExtra(ERIGHT);
        content = getIntent().getStringExtra(ECONTENT);
        hint = getIntent().getStringExtra(EHINT);
        if (title == null) {
            title = "";
        }
        if (right == null) {
            right = "";
        }
        if(content == null){
            content = "";
        }
        if(hint != null){
            etInput.setHint(hint);
        }
        tvTitle.setText(title);
        tvSend.setText(right);
        etInput.setText(content);
        etInput.setSelection(content.length());
        EditTextLimitUtils.lengthFilter(etInput,500,"不能超过500字");
    }

    @OnClick({R.id.tv_cancel, R.id.tv_send})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_cancel:
                closeKeyboard();
                finish();
                break;
            case R.id.tv_send:
                String content = etInput.getText().toString().trim();
                if(TextUtils.isEmpty(content) || content.length()<2){
                    ToastUtil.show(getString(R.string.input_content_tip));
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra(ECONTENT, content);
                setResult(100, intent);
                closeKeyboard();
                finish();
                break;
        }
    }
}
